package com.example.lawyer.databind.assembly;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;
import androidx.databinding.library.baseAdapters.BR;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.lawyer.R;
import com.example.lawyer.adapter.CurrentAdapters;
import com.example.lawyer.adapter.SlidePageAdapters;
import com.example.lawyer.databind.itemview.SlideImageData;

import java.util.ArrayList;
import java.util.List;

public class SlidePageViewData {


    public ObservableField<List<SlideImageData>> slidedata = new ObservableField<>();//轮播数据


    @BindingAdapter("setadapter")
    public static void SetAdapter(View view,List<SlideImageData> data)
    {
        if(data==null)
        {
            return;
        }

        ViewPager viewPager = (ViewPager) view;
        List<ImageView> imageViewlist = new ArrayList<>();
        RoundedCorners roundedCorners = new RoundedCorners(10);
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        for(int s=0;s<data.size();s++)
        {
            SlideImageData slideImageData = data.get(s);
            ImageView imageView = new ImageView(viewPager.getContext());
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            Glide.with(imageView).load(slideImageData.pagurl.get()).apply(options).into(imageView);
            imageViewlist.add(imageView);

        }
        SlidePageAdapters pageAdapters = new SlidePageAdapters(imageViewlist);
        viewPager.setAdapter(pageAdapters);

    }

}
